package com.example.ui_test.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.ui_test.R

class MyAdapter2 :RecyclerView.Adapter<BaseViewHolder>{
    private lateinit var mContext :Context
    var mList :MutableList<String> =ArrayList<String>()
    constructor(context: Context,list:MutableList<String>?){
        mContext=context
        if(list!=null)
        mList.addAll(list)
    }

    open fun setList(list:MutableList<String>?){
        mList.clear()
        if(list!=null)
            mList.addAll(list)
        notifyDataSetChanged()
    }
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder {
        val view = LayoutInflater.from(mContext).inflate(R.layout.item_rcl,parent,false)
        return BaseViewHolder(view)
    }

    override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
            val data=mList.get(position%mList.size)
        holder.setText(R.id.tv,data)
    }

    override fun getItemCount(): Int {
      return Int.MAX_VALUE
    }
}